#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

class Solution {
public:
    int consecutiveNumbersSum(int n) {
        int count = 0;

        /* 预处理 : 获取前缀和数组 */
        vector<long long int> preSum{};
        preSum.emplace_back(0);
        for (int idx = 1; idx <= n; idx++) {
            preSum.emplace_back(preSum.back() + idx);
        }

        int length = preSum.size();
        for (int splitNum = 1; splitNum <= n; splitNum++) {
            for (int idx = length - 1; idx >= 0; idx--) {
                if (idx - splitNum < 0) {
                    break;
                }

                int sumTmp = preSum[idx] - preSum[idx - splitNum];
                if (sumTmp == n) {
                    count++;
                    break;
                }
            }
            /* 是否进行下一次遍历判断 */
            int sumLast = preSum[splitNum] - preSum[0];
            if (sumLast >= n) {
                break;
            }
        }

        return count;
    }
};

int main() 
{
    Solution s;
    cout << s.consecutiveNumbersSum(5) << endl;
    return 0;
}